#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define uint unsigned int

#define YES cout << "YES" << '\n'
#define NO cout << "NO" << '\n'
#define endl '\n'
const int INF = 1e9;
const int MOD = 998244353;
using namespace std;

/*思考

*/
int cnt = 0, tmp = 0, idx = 0, a[1000005], f[1000005];
void solve() {
    int l, r;
    cin >> l >> r;
    cout << f[r] - f[l - 1] << endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 0;
    cin >> t;
    for (int i = 1; i <= 819; i++) {
        for (int j = 1; j <= i && cnt <= 1e6; j++) {
            tmp = i, idx = 0;
            while (tmp) {
                a[++idx] = tmp % 10;
                tmp /= 10;
            }
            for (int k = idx; k > 0; k--) {
                cnt++;
                f[cnt] = f[cnt - 1] + a[k];
            }
        }
    }
    while (t--) solve();
    return 0;
}